#ifndef DRON_TEST1_REDISSINGLETON_H
#define DRON_TEST1_REDISSINGLETON_H

#include <WinSock2.h>
#include "iostream"
#include "hiredis/hiredis.h"


using namespace  std;
class RedisSingleton {
private:

    redisContext  * redis_context;
    redisReply  * redis_reply;

    RedisSingleton(){

        cout<<"RedisSingleton init success"<<endl;

        struct timeval timeout = { 1, 500000 }; // 1.5 seconds
        redis_context=redisConnectWithTimeout("sensor.bodyta.com",6379,timeout);

        redis_reply = static_cast<redisReply *>(redisCommand(redis_context, "AUTH %s", "qhlk@2017"));
        printf("AUTH: %s\n", redis_reply->str);
        freeReplyObject(redis_reply);
    };
    ~RedisSingleton(){
        cout<<"destroy success"<<endl;
        freeReplyObject(redis_reply);
        redisFree(redis_context);
    };


public:
    static RedisSingleton & GetInstance(){
        static RedisSingleton instance;
        return instance;
    }
    string DoSomething();

};

#endif //DRON_TEST1_REDISSINGLETON_H
